cmake_minimum_required(VERSION 3.5)
project(swarm_avoid_client)

# 默认设置 C 和 C++ 标准
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Ofast -DNDEBUG -Wno-deprecated-declarations")

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

set(CMAKE_INCLUDE_PATH "/usr/include")
set(CMAKE_INSTALL_RPATH "/usr/local/lib")


# 查找依赖项
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(mavros_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(interfaces REQUIRED)
find_package(yolo_detect_message REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(GeographicLib REQUIRED)
find_package(nlohmann_json REQUIRED)

#find_path(GEOGRAPHICLIB_INCLUDE_DIR GeographicLib/Geocentric.hpp)
#find_library(GEOGRAPHICLIB_LIBRARY NAMES geographic PATHS /usr/local/lib)

# 添加 include 目录
include_directories(
  include
  ${EIGEN3_INCLUDE_DIR}
  #GeographicLib::GeographicLib
  #{GEOGRAPHICLIB_INCLUDE_DIR}
  ${PROJECT_SOURCE_DIR}/include
)

# 定义目标库
add_library(swarm_avoid
  # src/swarm_avoid_node.cpp
  src/swarm_avoid.cpp
  src/swarm_computer.cpp
  src/global_functions.cpp
)

# 链接库到可执行文件
target_link_libraries(swarm_avoid
  GeographicLib::GeographicLib
  nlohmann_json::nlohmann_json
)

set_target_properties(swarm_avoid PROPERTIES INSTALL_RPATH "/usr/local/lib")

ament_target_dependencies(swarm_avoid
  rclcpp
  sensor_msgs
  std_msgs
  geometry_msgs
  mavros_msgs
  nav_msgs
  interfaces
  yolo_detect_message
  #${GEOGRAPHICLIB_LIBRARY}
)

# 定义可执行文件
add_executable(node src/swarm_avoid_node1.cpp)

# 链接库到可执行文件
target_link_libraries(node
  swarm_avoid
)

# 声明依赖
ament_target_dependencies(node
  rclcpp
  sensor_msgs
  std_msgs
  geometry_msgs
  mavros_msgs
  nav_msgs
  interfaces
  yolo_detect_message
 # ${GEOGRAPHICLIB_LIBRARY}
)

# # 定义可执行文件
# add_executable(node2 src/swarm_avoid_node2.cpp)

# # 链接库到可执行文件
# target_link_libraries(node2
#   swarm_avoid
# )

# # 声明依赖
# ament_target_dependencies(node2
#   rclcpp
#   sensor_msgs
#   std_msgs
#   geometry_msgs
#   mavros_msgs
#   nav_msgs
#   interfaces
#   yolo_detect_message
#  # ${GEOGRAPHICLIB_LIBRARY}
# )

# # 定义可执行文件
# add_executable(node3 src/swarm_avoid_node3.cpp)

# # 链接库到可执行文件
# target_link_libraries(node3
#   swarm_avoid
# )

# # 声明依赖
# ament_target_dependencies(node3
#   rclcpp
#   sensor_msgs
#   std_msgs
#   geometry_msgs
#   mavros_msgs
#   nav_msgs
#   interfaces
#   yolo_detect_message
#   #${GEOGRAPHICLIB_LIBRARY}
# )



# add_executable(com
#   src/communication_multirotor.cpp   src/communication_multirotor_node.cpp )

# target_link_libraries(com
#   swarm_avoid
# )

# ament_target_dependencies(com 
#   geometry_msgs
#   rclcpp
#   std_msgs
#   yolo_detect_message
#   tf2
#   tf2_ros
#   tf2_geometry_msgs
#   mavros_msgs
# ) 

# 安装可执行文件和库
install(TARGETS swarm_avoid 
  # com
  node
  # node2
  # node3
  RUNTIME DESTINATION lib/${PROJECT_NAME}
  LIBRARY DESTINATION lib/${PROJECT_NAME}
)

# 安装 launch 文件夹
install(DIRECTORY launch config DESTINATION share/${PROJECT_NAME})

# 包声明
ament_package()
